Skip to content

feat(ai-openai): add gpt-image-2 to image model meta#625

Merged
AlemTuzlak merged 2 commits into
mainfrom
feat/openai-gpt-image-2
May 22, 2026
Merged

feat(ai-openai): add gpt-image-2 to image model meta#625
AlemTuzlak merged 2 commits into
mainfrom
feat/openai-gpt-image-2

Conversation

@AlemTuzlak
Copy link
Copy Markdown
Contributor

@AlemTuzlak AlemTuzlak commented May 22, 2026

Summary

  • Adds gpt-image-2 to OPENAI_IMAGE_MODELS so it can be selected through the openaiImage adapter (generate({ adapter: openaiImage(...), model: 'gpt-image-2', ... }))
  • Reuses the gpt-image-1 provider-options shape (quality, background, output_format, output_compression, moderation, partial_images) and size set (1024x1024, 1536x1024, 1024x1536, auto); the OpenAI docs for gpt-image-2 expose the same v1/images/generations + v1/images/edits endpoints with the same request parameters
  • Extends validateImageSize, validateBackground, and validatePrompt (32 000-char limit) to recognize the new model
  • Refreshes packages/typescript/ai/skills/ai-core/media-generation/SKILL.md and docs/media/image-generation.md to list gpt-image-2
  • Includes a minor changeset for @tanstack/ai-openai

Pricing source: OpenAI gpt-image-2 model page. Token-based pricing recorded in ModelMeta is text-input $5 / cached $1.25 / image-output $30 per 1M tokens; the schema does not have a separate field for the $8 image-input-token rate (same limitation as the existing gpt-image-1 entry).

Test plan

  • pnpm --filter @tanstack/ai-openai test:types
  • pnpm --filter @tanstack/ai-openai test:eslint (no new warnings/errors)
  • E2E coverage uses the existing image-generation spec running on gpt-image-1; the adapter call path is unchanged for gpt-image-2, so no new fixture was added. Add one if reviewers want gpt-image-2 exercised in CI.

Summary by CodeRabbit

  • New Features

    • Added support for OpenAI's gpt-image-2 model for image generation, available via the existing image adapter with the same options and sizes as current OpenAI image models.
  • Documentation

    • Updated docs to include gpt-image-2 in model options, sizes, availability, and adapter listings.
  • Bug Fixes

    • Restored web fetch capability for OpenRouter chat models so web-fetching tools remain available.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

Adds OpenAI gpt-image-2 model support: model metadata and export, provider option types and validation updates to accept gpt-image-2, documentation and changeset entries, and a separate fix restoring web_fetch capability in OpenRouter chat model typings.

Changes

GPT-Image-2 Model Support

Layer / File(s) Summary
Model metadata and type export
packages/typescript/ai-openai/src/model-meta.ts
Introduces GPT_IMAGE_2 constant (name gpt-image-2, knowledge cutoff, pricing, supported endpoints) and adds it to OPENAI_IMAGE_MODELS so OpenAIImageModel includes gpt-image-2.
Validation rules and type mappings
packages/typescript/ai-openai/src/image/image-provider-options.ts
Adds gpt-image-2 to OpenAIImageModelProviderOptionsByName and OpenAIImageModelSizeByName; updates validateImageSize, validateBackground, and validatePrompt to recognize gpt-image-2 (same sizes and 32,000-char prompt limit as other GPT image models).
User-facing and internal documentation
packages/typescript/ai-openai/src/adapters/image.ts, docs/media/image-generation.md, packages/typescript/ai/skills/ai-core/media-generation/SKILL.md, .changeset/openai-gpt-image-2.md
Updates adapter JSDoc to list gpt-image-2, adds gpt-image-2 to supported sizes and availability (1-10 images/request) in public docs, updates example to openaiImage('gpt-image-2'), and adds a changeset documenting usage and shared provider options.
OpenRouter tool capability typing fix
.changeset/openrouter-web-fetch-tool-capability.md, packages/typescript/ai-openrouter/src/model-meta.ts
Restores web_fetch in OpenRouterChatModelToolCapabilitiesByName so chat models declare both web_search and web_fetch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • TanStack/ai#582: Related OpenRouter tool-capability typing work restoring web_fetch.

Suggested reviewers

  • KevinVandy

Poem

🐰 A soft-hop cheer for images now new,
gpt-image-2 joins the creative view.
Sizes and prompts checked, metadata in line,
Docs and changelogs sing—everything's fine.
Hooray from a rabbit, with carrots and code too!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description is comprehensive and well-structured, covering changes, testing, and release impact. However, the provided description does not follow the template structure with 🎯 Changes, ✅ Checklist, and 🚀 Release Impact sections. Reformat the description to follow the repository template with proper section headings (## 🎯 Changes, ## ✅ Checklist, ## 🚀 Release Impact) for consistency and clarity.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding gpt-image-2 to the image model metadata for the ai-openai package, which is the primary objective of this PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/openai-gpt-image-2

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: lockfile failed supply-chain policy check. Run pnpm install locally to update the lockfile.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

🚀 Changeset Version Preview

2 package(s) bumped directly, 0 bumped as dependents.

🟨 Minor bumps

Package Version Reason
@tanstack/ai-openai 0.9.6 → 0.10.0 Changeset

🟩 Patch bumps

Package Version Reason
@tanstack/ai-openrouter 0.9.6 → 0.9.7 Changeset

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 22, 2026

View your CI Pipeline Execution ↗ for commit c32b43d

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-22 10:30:48 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 22, 2026

View your CI Pipeline Execution ↗ for commit c32b43d

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 8s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-22 10:06:59 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 22, 2026

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@625

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@625

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@625

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@625

@tanstack/ai-code-mode-skills

npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@625

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@625

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@625

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@625

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@625

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@625

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@625

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@625

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@625

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@625

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@625

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@625

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@625

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@625

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@625

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@625

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@625

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@625

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@625

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@625

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@625

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@625

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@625

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@625

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@625

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@625

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@625

commit: 65784fa

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/media/image-generation.md`:
- Line 93: The documentation's OpenAI model overview bullet list is missing
`gpt-image-2` causing inconsistency with the tables; update the overview bullet
list in image-generation.md to include `gpt-image-2` (matching the table row
that lists `gpt-image-2` and its sizes `1024x1024`, `1536x1024`, `1024x1536`,
`auto`) so the intro bullets and the detailed table are consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 13a5ffb1-ba94-451b-8c3b-1f5b2567f5df

📥 Commits

Reviewing files that changed from the base of the PR and between 27d30c9 and c32b43d.

📒 Files selected for processing (6)
  • .changeset/openai-gpt-image-2.md
  • docs/media/image-generation.md
  • packages/typescript/ai-openai/src/adapters/image.ts
  • packages/typescript/ai-openai/src/image/image-provider-options.ts
  • packages/typescript/ai-openai/src/model-meta.ts
  • packages/typescript/ai/skills/ai-core/media-generation/SKILL.md

Comment thread docs/media/image-generation.md
Adds `gpt-image-2` to OPENAI_IMAGE_MODELS so it can be used through
openaiImage adapters. Reuses the gpt-image-1 provider-options/size
shape (quality, background, output_format, output_compression,
moderation, partial_images; sizes 1024x1024 / 1536x1024 / 1024x1536
/ auto) and extends size + prompt-length validators. Also updates
the media-generation skill and image-generation doc page to list
the new model.
The model-metadata sync in #623 regenerated
`OpenRouterChatModelToolCapabilitiesByName` with `['web_search']` only,
which made `webFetchTool()` (added in #611) unassignable to any
OpenRouter text adapter and broke the per-model type-safety test.

Add `'web_fetch'` back so the existing tests compile.
@AlemTuzlak AlemTuzlak force-pushed the feat/openai-gpt-image-2 branch from c32b43d to 65784fa Compare May 22, 2026 10:29
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/typescript/ai-openai/src/image/image-provider-options.ts (1)

184-195: 🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Use Zod schemas as the single source of truth for image-model constraints.

packages/typescript/ai-openai/src/image/image-provider-options.ts hard-codes runtime rules in validateImageSize (e.g., validSizes), validateBackground (supportedModels), and validatePrompt (model-specific prompt limits), while OpenAIImageModelSizeByName separately defines/derives model/size constraints—yet this file contains no Zod schemas/imports. Move these model/size/background/prompt rules into Zod and infer the exported types/maps from that schema (to keep runtime and type-level constraints in sync).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/typescript/ai-openai/src/image/image-provider-options.ts` around
lines 184 - 195, The file currently duplicates model/size/background/prompt
rules across runtime validators and a separate OpenAIImageModelSizeByName type;
replace those hard-coded runtime lists by defining Zod schemas (e.g.,
ImageModelSchema, ImageModelConfigSchema) that declare each model's supported
sizes, backgrounds, and prompt constraints, import z from Zod, infer TypeScript
types via z.infer and derive the OpenAIImageModelSizeByName map from the schema,
then update validateImageSize, validateBackground, and validatePrompt to read
constraints from the Zod-backed config (or validate against the Zod schemas
directly) instead of using hard-coded validSizes/supportedModels/prompt limits
so runtime and type-level rules stay in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/typescript/ai-openai/src/image/image-provider-options.ts`:
- Around line 184-195: The file currently duplicates
model/size/background/prompt rules across runtime validators and a separate
OpenAIImageModelSizeByName type; replace those hard-coded runtime lists by
defining Zod schemas (e.g., ImageModelSchema, ImageModelConfigSchema) that
declare each model's supported sizes, backgrounds, and prompt constraints,
import z from Zod, infer TypeScript types via z.infer and derive the
OpenAIImageModelSizeByName map from the schema, then update validateImageSize,
validateBackground, and validatePrompt to read constraints from the Zod-backed
config (or validate against the Zod schemas directly) instead of using
hard-coded validSizes/supportedModels/prompt limits so runtime and type-level
rules stay in sync.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f365fb03-3b0a-40a2-a6ba-bcddaca7fc49

📥 Commits

Reviewing files that changed from the base of the PR and between c32b43d and 65784fa.

📒 Files selected for processing (8)
  • .changeset/openai-gpt-image-2.md
  • .changeset/openrouter-web-fetch-tool-capability.md
  • docs/media/image-generation.md
  • packages/typescript/ai-openai/src/adapters/image.ts
  • packages/typescript/ai-openai/src/image/image-provider-options.ts
  • packages/typescript/ai-openai/src/model-meta.ts
  • packages/typescript/ai-openrouter/src/model-meta.ts
  • packages/typescript/ai/skills/ai-core/media-generation/SKILL.md
✅ Files skipped from review due to trivial changes (5)
  • packages/typescript/ai-openai/src/adapters/image.ts
  • .changeset/openrouter-web-fetch-tool-capability.md
  • packages/typescript/ai/skills/ai-core/media-generation/SKILL.md
  • docs/media/image-generation.md
  • .changeset/openai-gpt-image-2.md

@AlemTuzlak AlemTuzlak merged commit ebdad7f into main May 22, 2026
10 checks passed
@AlemTuzlak AlemTuzlak deleted the feat/openai-gpt-image-2 branch May 22, 2026 10:43
@github-actions github-actions Bot mentioned this pull request May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant